package gameLogic;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import gameElements.GBall;
import gameElements.GBox;
import gameElements.GBrick;



import javax.swing.Timer;

/**
 * Track000.java
 * 
 * Fredrik Wallenius and Peter Steiner 
 * DP08 - KTH - 2009
 *
 */
public class Track000 extends TrackEngine{
	
	private Timer addBallTimer;
	
	public Track000(){
		super();
		this.trackName = "I've got balls! You got balls?";
		trackId = 0;
		addBallTimer = new Timer(5000, new addBall());
	}
	
	/**
	 * RUn once before start. Will give the ElementHandler the bricks and balls
	 * and other init data
	 */
	public void initiateTrack(){
		for(int pos = 10; pos <125; pos+=25){
			GBall a = new GBall((double) pos, (double) 200+ pos/2, Color.blue, 15.0, elHandler.getElements());
			a.setVelocity(8.0, 9.0);
			a.setBoundingBox(WIDTH, HEIGHT);
			elHandler.addGfxElement(a);
		}
		
		GBox b;
		
		for(int j = 100; j<205; j+=26){
			for(int i = 100; i<851; i+=76){											//Random hitbox upp to 3 hits
				b = new GBrick((float) i, (float) j, Color.green, 75.0, 25.0, true, true, (int)(Math.random()*4)+1);
				//b.setVelocity(0.0, 0.0);
				b.setBoundingBox(WIDTH, HEIGHT);
				elHandler.addGfxElement(b);
			}
		}
		
		
		super.initiateTrack();   // <-----  Do NOT remove!!!
	}
	
	public void start(){
		super.start();
		addBallTimer.start();
	}
	
	private class addBall implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			GBall b = new GBall(10.0, 200.0, Color.red, 15.0, elHandler.getElements());
			b.setVelocity(9.0, 8.0);
			b.setBoundingBox(WIDTH, HEIGHT);
			elHandler.addGfxElement(b);
		}
		
	}
	
	

}
